import ax from 'axios';

// 默认超时时间
ax.defaults.timeout = 30000;
// 跨域请求，允许保存cookie
ax.defaults.withCredentials = true;
// 基础url
// ax.defaults.baseURL = import.meta.env.VITE_APP_BASE_API;
// ax.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';

// HTTPrequest拦截
ax.interceptors.request.use(
	(config) => {
		return config;
	},
	(error) => {
		return Promise.reject(error);
	}
);

// HTTPresponse拦截
ax.interceptors.response.use(
	(res) => {
		return Promise.resolve(res.data);
	},
	(error) => {
		return Promise.reject(new Error(error));
	}
);

export default ax;
